package com.zyb.base.config;

import com.zyb.base.properties.CustomProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CorsFilter;

import javax.sql.DataSource;

/**
 * @author ZhuYouBin
 * @version 1.0.0
 * @Date: 2022/11/13 13:07
 * @Description 自动配置类
 */
@Configuration
@EnableConfigurationProperties(value = {CustomProperties.class})
public class CustomAutoConfig {
    private static final Logger logger = LoggerFactory.getLogger(CustomAutoConfig.class);

    /**
     * 默认自动装配
     */
    @Bean
    @ConditionalOnProperty(prefix = "custom.spring", name = "fastjson", matchIfMissing = true)
    public HttpMessageConverters fastjsonHttpMessageConverters() {
        return FastjsonAutoConfig.fastjsonHttpMessageConverters();
    }

    /**
     * 默认自动装配
     */
    @Bean
    @ConditionalOnProperty(prefix = "custom.spring", name = "cors", matchIfMissing = true)
    public FilterRegistrationBean<CorsFilter> corsFilter() {
        return CorsAutoConfig.corsFilter();
    }
}
